package com.epoint.mobileoa.tools.dialog;

import com.epoint.mobileoa.R;

import net.londatiga.android.ActionItem;
import net.londatiga.android.QuickAction;

import android.content.Context;
import android.view.View;

/**
 * @author liyc
 * @time 2012-12-19 下午2:48:37
 * @annotation 快速弹出对话框
 */
public class QuickActionDialog {

	/**
	 * @param con 上下文
	 * @param v 点击事件触发的视图
	 * @param icons 图标数组
	 * @param titles 标题数组
	 * @param listener 选择事件
	 */
	public QuickActionDialog(Context con,View v,int[] icons,String[] titles,final OnItemClickListener listener)
	{

		final QuickAction qa = new QuickAction(v);


		if(icons!=null&&icons.length!=titles.length)
		{
			icons = null;
		}

		for(int i=0;i<titles.length;i++)
		{
			final int mi = i;
			ActionItem ai = new ActionItem();
			ai.setTitle(titles[i]);

			if(icons!=null)
			{
				ai.setIcon(con.getResources().getDrawable(icons[i]));
			}
			else{
				ai.setIcon(con.getResources().getDrawable(R.drawable.img_null_48));
			}

			ai.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View v) {
					listener.onClick(mi);
					qa.dismiss();
				}
			});
			qa.addActionItem(ai);
		}
		qa.show();
	}

	public QuickActionDialog(Context con,View v,String[] titles,final OnItemClickListener listener)
	{
		this(con,v,null,titles,listener);
	}

	public interface OnItemClickListener
	{
		/**
		 * @param which 代表选择的第几列，索引从0开始
		 */
		public void onClick(int position);
	}

}
